package com.yaozheng.vocationaltraining.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.adapter.DiSanZheZeRenXianListAdapter;
import com.yaozheng.vocationaltraining.adapter.DownPaymentPercentListAdapter;
import com.yaozheng.vocationaltraining.bean.BaoXianBean;
import com.yaozheng.vocationaltraining.bean.CarDetailBean;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

/**
 * Created by moon on 2017/11/22.
 */
@EFragment(R.layout.activity_disanzhezerenxian)
public class DiSanZheZeRenXianFragment extends BaseFragment {
//    public CarDetailBean getCarDetailBean() {
//        return carDetailBean;
//    }
//
//    public void setCarDetailBean(CarDetailBean carDetailBean) {
//        this.carDetailBean = carDetailBean;
//    }
//
//    CarDetailBean carDetailBean;

    @ViewById
    ListView listView;

    LayoutInflater inflater;
    @ViewById
    TextView headTitleText;

    DiSanZheZeRenXianListAdapter diSanZheZeRenXianListAdapter;

    @AfterViews
    public void initView() {
        headTitleText.setText("第三者责任险");
        inflater = this.getActivity().getLayoutInflater();

        diSanZheZeRenXianListAdapter = new DiSanZheZeRenXianListAdapter(this.getActivity(),
                PriceFragment.carDetailBean.getDisanzhezerenxian());
        listView.setAdapter(diSanZheZeRenXianListAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                diSanZheZeRenXianListAdapter.setselectedPosition(i);
                for(BaoXianBean bean : PriceFragment.carDetailBean.getDisanzhezerenxian()){
                    bean.setDefaultStatus("0");
                }
                PriceFragment.carDetailBean.getDisanzhezerenxian()
                        .get(i).setDefaultStatus("1");

                PriceFragment.carDetailBean.setWuguozerenxian((int)(PriceFragment.carDetailBean.getDisanzhezerenxian()
                        .get(i).getValue() * 20 / 100));

                PriceFragment.carDetailBean.setBujimianpeiteyuexian((int)((PriceFragment.carDetailBean.getCheliangshunshixian()+PriceFragment.carDetailBean.getDisanzhezerenxian()
                        .get(i).getValue())
                            *20 / 100)
                    );


                ((HomeActivity)DiSanZheZeRenXianFragment.this.getActivity()).backClick();
            }
        });



    }

}
